<?php

namespace App\Admin\Controllers;

use App\Admin\Grid\NGrid;
use App\Admin\Service\RefundService;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Grid\Displayers\Actions;
use Encore\Admin\Show;

class RefundController extends AdminController
{
    private RefundService $service;

    /**
     * @param RefundService $service
     */
    public function __construct(RefundService $service)
    {
        $this->service = $service;
    }

    /**
     * grid
     * @return NGrid
     */
    protected function grid(): NGrid
    {
        $this->service->grid();
        $this->service->column('serialNumber,paymentId,outRefundNo,refundId,amount,createdAt');
        $this->service->grid->column('result', __('refund.result'))->display(function ($column) {
            return view('json', ['json' => $column]);
        });
        $this->service->grid->disableActions(false);
        $this->service->grid->actions(function (Actions $action) {
            $action->disableDelete();
            $action->disableView(false);
            $action->disableEdit();
        });
        return $this->service->grid;
    }

    /**
     * detail
     * @param int $id
     * @return Show
     */
    protected function detail(int $id): Show
    {
        $this->service->show($id);
        $this->service->field('serialNumber,paymentId,outRefundNo,refundId,amount,remark,createdAt');
        $this->service->show->field('result', $this->service->ml['result'])->json();
        return $this->service->show;
    }
}
